package com.example.demo.redis;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("redis")
public class RedisController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * redis订阅发布测试
     */
    @GetMapping("test")
    public void test(){
        long id = Thread.currentThread().getId();
        for (int i=0; i< 500; i++){
            stringRedisTemplate.convertAndSend("channel:test", "hello-word-"+i+"-"+id);
        }

    }
}
